#-------------------------------------------------------------------------------
`
Run this function to solve the model with perfect information
It solves the model with both constant and alternating types
`
#-------------------------------------------------------------------------------

#-------------------------------------------------------------------------------
#Load functions
using Interpolations, Optim, Roots, JLD, Plots
using Distributions, StatsBase
include("01_Model_Structure.jl");
include("02_Functions.jl")
include("03_Model.jl")
include("04_Main_Iteration_fx.jl");
#-------------------------------------------------------------------------------

#-------------------------------------------------------------------------------
#Solve the model with Perfect Information
#-------------------------------------------------------------------------------

for do_ConsTypes = 0:1

    println(" --------------- SOLVING PERFECT INFO MODEL ---------------")
    if do_ConsTypes==0
    @printf("Alternating types \n")
    else
    @printf("Constant types \n")
    end
    println("-----------------------------------------------------------")
    print("\n")
    # Load Economy
    # Make sure parameters are the same as those for the baseline model
    #--------------------------------------------------------------------------
    name_file = string("CE_model_structure_alpha_",0.028,".jld")
    ce_base   = load(string("../01_Baseline_Model/model_data/",name_file), "ce")
    ce = ce_economy_pinf( r   = ce_base.r,
                          β   = ce_base.β,
                          γ   = ce_base.γ,
                          θ   = ce_base.θ,
                          σ_d = ce_base.σ_d,
                          nb1 = ce_base.nb1,
                          nb2 = ce_base.nb2,
                          ny  = ce_base.ny,
                          zb         = ce_base.zb,
                          mb         = ce_base.mb,
                          Bval       = ce_base.Bval,
                          π_min      = ce_base.π_min,
                          d0         = ce_base.d0,
                          d1         = ce_base.d1,
                          ε          = ce_base.ε,
                          NQ         = ce_base.NQ,
                          η          = ce_base.η,
                          ρ          = ce_base.ρ,
                          damp       = 0.85,
                          maxiter    = 1000,
                          save_final = 1 )
    ce_base = [];
    #--------------------------------------------------------------------------

    #Case of Constant Types
    #------------------------------------
    if do_ConsTypes==1
    ce.ΠT = eye(2)
    end

    # Solve the model
    #------------------------------------
    iterate_VF(ce, tol_max=1e-4)

    #Save results
    #------------------------------------
    name_file = ifelse(do_ConsTypes==0, string("CE_model_PerfInfo.jld"), string("CE_model_ConsTypes.jld") )
    save(string("model_data/",name_file), "ce", ce)
end
#----------------------------------------------------------------------------------------------
